function [dm options logic av]= initBlock(dataFileName, taskPhase, cbal)


% choose display
% -1 for full screen on highest-number display
% 0 for smaller window
% 0-1 for translucent, or integer for other connected displays.


%% NEED TO FIGURE OUT HOW TO DO THIS STUFF...
% % dm = dotsTheDrawablesManager.theObject();
% % dm.setScreenProperty('displayIndex', -1); 
% % 
% % 
% % % screen measurements
% % % set width, height, and viewing distance in arbitrary units to compute
% % % mapping to degrees of visual angle.
% % % can change display size by varying distance
% % dm.setScreenProperty('width', 1);
% % dm.setScreenProperty('height', 1);
% % dm.setScreenProperty('distance', 1.8); %%% increase this to enlarge
dm=1;

% Organize predictive inference logic with a custom object
possibleSigma = [10, 25];
sigma = possibleSigma(cbal); % controls blockStds AND explStd AND holeWidth
time = clock;
randSeed = time(6)*10e6;
logic = PredInfLogic(randSeed);
logic.name = 'Predictive Inference Helicopter';



logic.dataFileName = dataFileName;
% logic.dataFileName = 'dummydata';
logic.time = time;
logic.blockHazards = [1 1 1 1] * 0.125;
logic.safetyTrials = 3;
logic.blockStds = [1 1 1 1] * sigma;
logic.trialsPerBlock = 10;
logic.isBlockShuffle = false;
logic.fixedOutcomes = [];
logic.maxOutcome = 300;
logic.isPredictionReset = false;
logic.isPredictionLimited = false;


% The task has many input and flow options
options.isKeyboardTrigger = true;
options.triggerKeyName = 'KeyboardT';
options.triggerMaxWait = Inf;
options.isPositionMapping = false;
options.isBucketPickup = false;
options.bucketPickupRange = [1 1]*logic.maxOutcome;


% try this with the fMRI non-metal joystick
%   omit the "commit" field to require subject to wait
options.gamepadButtons.leftFine = 2;
options.gamepadButtons.rightFine = 3;
% options.gamepadButtons.commit = 3;
options.gamepadButtons.info = 4;
options.gamepadButtons.abort = 5;
options.gamepadCalibration = {[100 860], [], [-1, +1]};


% Choose the Helicopter look and feel
av = PredInfAVHelicopter();


% av.drawables.addCall({@dotsTheScreen.reset, 'displayIndex', 1}, 'fullscreen');
% av.drawables.callByName('fullscreen');
% 


av.pleaseWaitString = 'Please wait.';
av.pleasePressString = 'Zum Starten gruene Taste druecken.';


av.isCloudy = true;
av.width = 30;
av.height = 20;
av.backgroundWidth = av.width;
av.backgroundHeight = 15;
av.cloudsHeight = 5;
av.yHelicopter = (av.backgroundHeight/2) - (av.cloudsHeight/2);
av.yClouds = av.yHelicopter;
av.logic = logic;
av.coins = struct( ...
    'name', {'gold', 'rocks'}, ...
    'color', {[1.0 0.84 0], [0.7 0.7 0.8]}, ...
    'value', {1, 0}, ...
    'frequency', {1 1});
%     'name', {'gold', 'silver', 'bronze'}, ...
%     'color', {[1.0 0.84 0], [0.7 0.7 0.8], [0.8 0.5 0.2]}, ...
%     'value', {2, 1, 0}, ...
%     'frequency', {1 1 1});

av.inactivePrediction = logic.maxOutcome;


% choose timing which applies to audiovisual elements and flow states
%
%%% TIMING NOTE:
% Specifying a total of 4.25 sec below results, in practice, in trials
% about 4.8 sec long. This equals 25 trials per 2 minutes. 
%
av.tIdle = Inf; % time till task begins of subject does not respond
av.tPredict = 0; 
av.tUpdate = 20; % time available for subject to enter a prediction
av.tCommit = 0; % time locked prediction is displayed before outcome
av.tOutcome = 1; % duration of outcome
av.tDelta = 0;
av.tSuccess = 0;
av.tFailure = 0;


% control the spatial cost function
bucketSDs = 3; % width of the bucket, in SDs of the payoff distribution
av.holeWidth = bucketSDs*av.width * sigma/logic.maxOutcome; % set bucket width
av.explStd = av.width * sigma/logic.maxOutcome; % set payoff SD = noise SD


% control parameters that depend on the specified taskPhase
% taskPhase is a string. possible values:
% 'behavInit1','behavInit2','behavMain','mrInit','mrMain'

% 'heliVis', 'cloudy', 'main'


switch taskPhase 
    case 'demo'
        av.isCloudy = false;  
    case 'heliVis' % long w/ helicopter visible
        av.isCloudy = false;
        logic.nBlocks = 1;
        options.isKeyboardTrigger = false;
        logic.trialsPerBlock = 200; % normally 80 (~6 min)
        logic.learnCritOn=1;
        logic.learnCritNumT =10;
        logic.learnCritThresh=9;
        logic.learnCritTolerance=2;
        %    av.pleasePressString = 'Bleiben Sie unter dem Hubschrauber. // Zum Starten gruene Taste druecken.';
        
    case 'cloudy' % long w/ helicopter visible
        av.isCloudy = true;
        logic.catchTrialProbability=.1;
        logic.nBlocks = 1;
        logic.trialsPerBlock = 40; % normally 80 (~6 min)
        options.isKeyboardTrigger = false;
        
    case 'main' % long, multi-block, helicopter hidden
        av.isCloudy = true;
        logic.catchTrialProbability=.1;
        logic.nBlocks = 1;
        logic.trialsPerBlock = 200; % normally 80 (~6 min)
        options.isKeyboardTrigger = false;
end


% try out av behaviors without user input
%